package gll.pub.onepeas.models

import org.springframework.data.annotation.Id
import org.springframework.data.annotation.Transient
import org.springframework.data.relational.core.mapping.Column
import org.springframework.data.relational.core.mapping.Table
import java.time.LocalDateTime
import java.util.UUID

const val baseImageUrl = "https://test-1251228670.cos.ap-beijing-1.myqcloud.com/"

@Table("users")
data class UsersTable(
    @Id
    var id: UUID? = null,
    @Column("username")
    var username: String = "一豆_${generateRandomString(6)}",
    @Column("password")
    var password: String = "",
    @Column("phone")
    var phone: String = "",
    @Column("head_image")
    var headImage: String = "def.png",
    @Column("created_at")
    var createdAt: LocalDateTime = LocalDateTime.now(),
    @Column("grade")
    var grade: Int = 0,
    @Column("identity")
    var identity: Int = 0,

){
    var imageBaseUrl: String? = baseImageUrl
        @Transient
        get() = baseImageUrl
}
fun generateRandomString(len: Int = 15): String{
    val alphanumerics = CharArray(26) { it -> (it + 97).toChar() }.toSet()
        .union(CharArray(9) { it -> (it + 48).toChar() }.toSet())
    return (0 until len).map {
        alphanumerics.toList().random()
    }.joinToString("")
}